package operation.modules.operation.controller;

import operation.modules.operation.dto.ColumnDTO;
import operation.modules.operation.entity.DbProjectEntity;
import operation.modules.operation.service.DatabaseManageService;
import operation.util.ReqResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
* 数据库管理 Controller
*/
@RestController
@RequestMapping("api/operation/database-manage")
public class DatabaseManageController {
    @Autowired
    private DatabaseManageService databaseManageService;

    /**
     * 查询数据库所有表
     */
    @RequestMapping("/all-database")
    public ReqResult allDatabase() {
        List<DbProjectEntity> list = databaseManageService.queryAllDateBase();
        return ReqResult.ok().put("list", list);
    }

    /**
     * 查询指定表所有字段
     */
    @RequestMapping("/all-column")
    public ReqResult allColumn(@RequestParam Map<String, Object> params) {
        List<ColumnDTO> list = databaseManageService.queryAllColumn(params);
        return ReqResult.ok().put("list", list);
    }
}